package com.jvyou.common.core.domain.model;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @author 橘柚
 * @since 2025/3/4 17:37
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResult<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 2761920885140294992L;

    private Long total;

    private List<T> data;

    private Boolean success;

    public static <T> PageResult<T> success(Long total, List<T> data) {
        return new PageResult<>(total, data, true);
    }

    public static <T> PageResult<T> success(IPage<T> page) {
        return new PageResult<>(page.getTotal(), page.getRecords(), true);
    }

    public static <T> PageResult<T> empty() {
        return new PageResult<>(0L, Collections.emptyList(), true);
    }
}
